using UnityEngine;

namespace Gj
{
    public class BindHelper : NodeHelper
    {
        public Camera Camera;
        public GameObject obj;
        public bool scale;
        public bool invert;
        public float number;
        public float max;
        private bool allow;

        protected override BindDataType bindDataType => BindDataType.Bool;

        private void Update()
        {
            if (!allow) return;
            Refresh();
        }

        protected override void BindData(bool b)
        {
            allow = invert ? !b : b;
        }

        private void Refresh()
        {
            transform.position = Camera.WorldToScreenPoint(obj.transform.position);
            if (scale)
            {
                var size = (max - Camera.transform.position.y * number) / 100;
                transform.localScale = new Vector3(size, size, size);
            }
        }
        

        public void SetObj(GameObject o)
        {
            obj = o;
            Refresh();
        }
    }
}